﻿HmJS.$Import('ui.Picker');
//HmJS.$Import('core.domready');

HmJS.register('demo.module.ui.calendar.datepicker.pickerposition', function ($ns) {
	var that = {};

	that.todo = function () {

		var Picker = $ns.ui.Picker;

		pickers[1] = new Picker({
			positionOffset: { x: 20, y: 10 }
		}).position(20, 200);

		var positions = ['top', 'right', 'bottom', 'left'];
		$$('#relative a').each(function (el, i) {
			el.addEvent('click', function (event) {
				event.stop();
				myPicker.open().position(el, positions[i]);
			});
		});

		$('open').addEvent('click', function (e) {
			e.stop();
			myPicker.open();
		});
		$('close').addEvent('click', function (e) {
			e.stop();
			myPicker.close();
		});
		$('toggle').addEvent('click', function (e) {
			e.stop();
			myPicker.toggle();
		});

		pickers[2] = new Picker({
			inject: $('relative')
		}).close(true);

		myPicker = pickers[1];

		$('picker').addEvent('change', function () {
			myPicker.close();
			myPicker = pickers[this.get('value')];
			myPicker.open();
		})

	};

	return that;
});
